//
//  AdviceViewController.m
//  SHShopping
//
//  Created by 坤鼎 on 2019/9/2.
//  Copyright © 2019 kunding. All rights reserved.
//

#import "AdviceViewController.h"

@interface AdviceViewController () <UITextViewDelegate>

@property (nonatomic, strong) UIButton *btn;
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UILabel *lb;
@property (nonatomic, assign) NSInteger LimitMaxWord;

@end

@implementation AdviceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"意见反馈";
    
    self.LimitMaxWord = 120;
    
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 18, SCREEN_WIDTH, 160)];
    self.textView = textView;
    textView.text = @"    说说你的问题";
    textView.textColor = [UIColor grayColor];
    
    textView.delegate = self;
    [self.view addSubview:textView];
    
    UILabel *lb = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 26 - 60, 135, 60, 15)];
    self.lb = lb;
    lb.text = @"0/120";
    lb.font = FONT(12);
    lb.textAlignment = 2;
    lb.textColor = UIColorFromRGB(0x333333);
    [textView addSubview:lb];


    
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 160) / 2, 22 + GetViewYH(textView), 160, 44)];

    [btn gradientViewColorArray:@[] pointArr:@[]];
    
    [btn setTitle:@"提交" forState:UIControlStateNormal];
    [self.view addSubview:btn];
    self.btn = btn;
    self.btn.alpha = 0.5;
    self.btn.userInteractionEnabled = NO;
    
    [btn addTarget:self action:@selector(actionBtn) forControlEvents:UIControlEventTouchUpInside];
}

- (void)actionBtn {
    
    if (_textView.text.length < 6) {
        [SXLoadingView showAlertHUD:@"至少6个字哟" duration:1];
        return;
    }
    NSDictionary *par = @{@"count":self.textView.text};
    [SXLoadingView showProgressHUD:nil];
    [PPNetworkHelper POST:URL_insertOpinion parameters:par success:^(id responseObject) {
        [SXLoadingView showAlertHUD:@"感谢您的反馈，我们会认真参考您的宝贵意见" duration:3];
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError *error) {
        [SXLoadingView showAlertHUD:SXLoadingErrorStr duration:SXLoadingErrorTime];
    }];
}

- (void)textViewDidBeginEditing:(UITextView *)textView {
    textView.text = nil;
    self.btn.userInteractionEnabled = YES;
    self.btn.alpha = 1;
    self.textView.textColor = [UIColor blackColor];
}

- (void)textViewDidChange:(UITextView *)textView {
    self.lb.text = [NSString stringWithFormat:@"%ld/120", textView.text.length];
}

@end
